﻿<UserControl x:Class="XWord.GUI.Views.Fundamental.CategoryExplorerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:inf="http://www.grandsys.com/luna"
             xmlns:info="http://schemas.xword.com/winfx/xaml/info"
             
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key="CategoryListBox" TargetType="ListBox">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <WrapPanel>
                            
                        <TextBlock Text="{Binding Key}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type ListBox}, Mode=FindAncestor}}">
        					<TextBlock.ContextMenu>
        						<ContextMenu
        							cal:Action.TargetWithoutContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Mode=Self}}">
        							<MenuItem Header="导入" cal:Message.Attach="EmportWord"/>
                                    <MenuItem Header="新增" cal:Message.Attach="OpenNewDialog"/>
        							<MenuItem Header="修改" cal:Message.Attach="OpenEditDialog"/>
        							<MenuItem Header="删除" cal:Message.Attach="Delete"/>
        						</ContextMenu>
        					</TextBlock.ContextMenu>
                            <TextBlock Margin="2,0,0,0" Text="{Binding Value[List].Count,StringFormat=({0})}"></TextBlock>
                        </TextBlock>
                        </WrapPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <inf:DockingWindowMetadata.Instance>
        <inf:DockingWindowMetadata Title="{Binding DisplayName}" IsToolWindow="True" DefaultDock="Right"
                                    CanClose="False" CreateNewDockingGroup="True" />
    </inf:DockingWindowMetadata.Instance>
  
        <ListBox  x:Name="Element_CategoryList" Style="{StaticResource CategoryListBox}"
                  cal:Message.Attach="[Event Drop] = [Action AddWord($eventArgs,$eventArgs.Data)];
                  [Event SelectionChanged] = [Action SetCategoryWord($this.SelectedItem)]"
        					ItemsSource="{Binding CategoryList}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <info:ReadOnlyPropertyAction Property="SelectedItem" BindablePropertyItem="{Binding SelectedItem, Mode=TwoWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>
    
</UserControl>
